﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>驰骋工作流</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="./Scripts/bootstrap/js/jquery.min.js"></script>
    <script src="./Scripts/QueryString.js" type="text/javascript"></script>
    <link href="../DataUser/Style/ccbpm.css" rel="stylesheet"  type="text/css" />
    <!-- 引用通用的js文件. -->
    <script type="text/javascript" src="./Scripts/config.js"></script>
    <script type="text/javascript" src="./Comm/Gener.js"></script>
    <script type="text/javascript" language="javascript" >

        //页面启动函数.
        var str = location.href; //取得整个地址栏
        var num = str.indexOf("?");
        str = str.substr(num + 1);
        //流程编号
        var FK_Flow = GetQueryString("FK_Flow");
        //工作ID
        var WorkID = GetQueryString("WorkID");
        //节点编号
        var FK_Node = parseInt(GetQueryString("FK_Flow") + "01");
        //前置导航的模式
        var StartGuideWay = GetQueryString("StartGuideWay");

        $(function () {
            var url = MyFlow + "?DoType=StartGuide_Init&" + str + "&m=" + Math.random();
            //执行加载
            StartGuide_Init(url, FK_Flow, FK_Node, WorkID);
        });

        //关键字查询
        function KeyOfSearch() {
            //获取要查询的关键字
            var key = document.getElementById('TB_Key').value;
            var url = MyFlow + "?DoType=StartGuide_Init&" + str + "&Keys=" + key + "&m=" + Math.random();
            //执行查询
            StartGuide_Init(url, FK_Flow, FK_Node, WorkID);
        }

        //发起
        function SendMulit() {

            //获取选中的checkbox
            var rdVal = "";
            var cbVal = "";
            //循环取值
            $("input[name='BySQLMulti']:checked").each(function () {
                cbVal = "'" + $(this).val() + "'," + cbVal + "";
            });
            rdVal = cbVal;
            //替换潜在的错误
            rdVal = rdVal.replace("undefined", "");

            var url = MyFlow + "?DoType=StartGuide_MulitSend&" + str + "&Keys=" + rdVal + "&m=" + Math.random();

            $.ajax({
                type: 'post',
                async: true,
                url: url,
                dataType: 'html',
                success: function (data) {
                    //出现异常，提示错误
                    if (data.indexOf('err@') == 0) {
                        alert(data);
                        return;
                    }
                    //跳转
                    var href = "MyFlow.htm?FK_Flow=" + FK_Flow + "&FK_Node=" + FK_Node + "&WorkID=" + WorkID + "&Nos=" + data + "&IsCheckGuide=1";
                    window.location.href = href;
                }
            });
        }
        //加载方法
        function StartGuide_Init(url, FK_Flow, FK_Node, WorkID) {

            $.ajax({
                type: 'post',
                async: true,
                url: url,
                dataType: 'html',
                success: function (data) {
                    data = JSON.parse(data);
                    //选中的超链接及参数
                    var href = "MyFlow.htm?FK_Flow=" + FK_Flow + "&FK_Node=" + FK_Node + "&WorkID=" + WorkID + "&IsCheckGuide=1";
                    var _Html = "";
                    //判断是否出现异常
                    if (data.indexOf('err@') == 0) {

                        _Html += "<tr><td>";
                        _Html += "" + data + "";
                        _Html += "</td></tr>";

                        $('#dataList').html([_Html].join(''));
                        return;
                    }

                    //循环取出来的数据
                    for (var i in data) {
                        var key; var Name;
                        var thHtml = "<tr><th>Idx</th>";
                        //如果是第一行，先生成table列名
                        if (i < 1) {
                            for (var k in data[i]) {
                                if (k == "NO" || k == "No") {//No这一列，不显示
                                    key = data[i][k];
                                }
                                else if (k == "NAME" || k == "Name") {
                                    Name = data[i][k];
                                    thHtml += "<th>NAME</th>";
                                }
                                else {
                                    thHtml += "<th>" + k + "</th>";
                                }
                            }
                            _Html += thHtml + "</tr>";
                        }
                        //添加要显示的数据
                        _Html += "<tr>";

                        //如果是SQL多条模式，增加勾选框
                        if (StartGuideWay == "BySQLMulti") {
                            if (data[i]["NO"] == null || data[i]["NO"] == '' || data[i]["NO"] == undefined || data[i]["NO"] == "undefined")
                                _Html += "<td class='Idx' nowrap><input type='checkbox' name='BySQLMulti' value='" + data[i]["No"] + "' id='" + data[i]["No"] + "' />" + (parseInt(i) + parseInt(1)) + "</td>";
                            else
                                _Html += "<td class='Idx' nowrap><input type='checkbox' name='BySQLMulti' value='" + data[i]["NO"] + "' id='" + data[i]["NO"] + "' />" + (parseInt(i) + parseInt(1)) + "</td>";
                        }
                        else {
                            _Html += "<td class='Idx' nowrap>" + (parseInt(i) + parseInt(1)) + "</td>";
                        }

                        //根据sql查询的列名，依次显示，并对应列名
                        for (var v in data[i]) {
                            if (v == "NO" || v == "No") {//此处No列不显示
                                key = data[i][v];
                            }
                            else if (v == "NAME" || v == "Name") {

                                if (key.length < 0)//如果No没有在Name列之前，就去读josn中指定的对象值
                                    key = data[i]["NO"];
                                if (key == null || key == '' || key == undefined || key == "undefined")
                                    key = data[i]["No"];
                                _Html += "<td nowrap>";
                                //如果是SQL多条模式，去掉超链接
                                if (StartGuideWay == "BySQLMulti") {
                                    _Html += "" + key + "-" + data[i][v] + ""; //No,Name一起显示在Name列中
                                }
                                else {
                                    _Html += "   <a href='" + href + "&KeyNo=" + key + "' target='_self'>";
                                    _Html += "" + key + "-" + data[i][v] + ""; //No,Name一起显示在Name列中
                                    _Html += "</a>";
                                }
                                _Html += "</td>";
                            }
                            else {
                                _Html += "<td nowrap> " + data[i][v] + "</td>"; //显示其他列
                            }
                        }
                        _Html += "</tr>";
                    }

                    //在容器中显示
                    $('#dataList').html([
                        _Html
                    ].join(''));

                    //如果是SQL多条模式，增加发送按钮
                    if (StartGuideWay == "BySQLMulti") {
                        var sendMultiHtml = "<tr><td><input type='button' name='pub_Send' value='发起' id='Btn_Send' onclick='SendMulit()'/></td></tr>";
                        $("#mainTable tr:last").after(sendMultiHtml);
                    }
                }
            });
        }
    </script>
</head>
<body  >

<form id="cc">
    <div id="mainPanel" region="center" border="true" class="mainPanel">
        <table id="mainTable" style=" width:100%;">
            <caption id="cap_Title"></caption>
            <tbody>
                <tr>
                    <td class="ToolBar">
                        输入关键字:
                        <input name="TB_Key" type="text" id="TB_Key" />
                        <input type="button" name="pub_Btn" value="查询" id="Btn_Search" onclick="KeyOfSearch()" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <table id="dataList" style=" width:100%;">
                            
                        </table>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</form>

</body>
</html>
